import {useState, useEffect} from "react";
import {HTTP} from '@/utils/HTTP.js'

const useUserList = () => {
    const [userList, setUserList] = useState([])

    // console.log(res)
    useEffect(() => {

        async function getUserList() {
            const res = await HTTP({
                url: '/Allin/admin',
                method: 'GET'
            })
            const tableData = []
            for (let i = 0; i < res.data.length; i++) {
                let update = new Date(res.data[i].updatedAt)
                let created = new Date(res.data[i].createdAt)
                const uptime = update.getFullYear() + "年" + (update.getMonth() + 1) + "月" + ("0" + update.getDate()).slice(-2) + "日" + "-" + (update.getHours()) + "时" + (update.getMinutes()) + "分";

                const creative = created.getFullYear() + "年" + (created.getMonth() + 1) + "月" + ("0" + created.getDate()).slice(-2) + "日" + "-" + (created.getHours()) + "时" + (created.getMinutes()) + "分";

                res.data[i].updatedAt = uptime
                res.data[i].createdAt = creative
                tableData.push(res.data[i])
            }
            setUserList(res.data)
        }

        getUserList()

    }, [])

    return {userList}
}

export default useUserList